package ru.urfc.portal.ui.client.googlets.client;

import ru.urfc.portal.ui.client.BaseGooglet;
import ru.urfc.portal.ui.client.Style;
import ru.urfc.portal.ui.client.controllers.GridController;
import ru.urfc.portal.ui.client.controllers.events.GetEvent;
import ru.urfc.portal.ui.client.descriptor.GridDescriptor;
import ru.urfc.portal.ui.client.descriptor.GridField;
import ru.urfc.portal.ui.client.widgets.DateFilter;
import ru.urfc.portal.ui.client.widgets.MegaGrid;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.shared.GwtEvent.Type;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Widget;

public class BalanceOperationList extends BaseGooglet {

	interface Binder extends UiBinder<Widget, BalanceOperationList> {}
	private static Binder binder = GWT.create(Binder.class);

	@UiField Style style;
	@UiField Element title;
	@UiField DateFilter dateFilter;
	@UiField MegaGrid grid;
//	@UiField(provided = true) PagingToolBar paging = new PagingToolBar(PAGING_SIZE);
	@UiField Button search;

	public Type<GridController> SEARCH = new Type<GridController>();

	@UiHandler("search")
	void search(ClickEvent e) {
		getEventsDispatcher().fireEvent(new GetEvent(SEARCH));
	}	
	
	@Override
	protected void init() {
		initWidget(binder.createAndBindUi(this));
		title.setInnerText("Баланс");
		dateFilter.setupButton(search.getElement());

		GridDescriptor descriptor = new GridDescriptor(BALANCE_OPERATION, CLIENTS, getClientId(), BALANCE_OPERATIONS);
		GridField autoExpandColumnField = descriptor.addTextColumn("name", "Операция", 200);
		descriptor.addDateColumn("date", "Дата", 100);
		descriptor.addMoneyColumn("amountWithSign", "Сумма", 100);
		descriptor.addMoneyColumn("balance", "Остаток", 100).getDblRenderer().setRedGreenColorer(style);
		
//		createController(descriptor, grid, paging);
		register(SEARCH, createController(descriptor, grid)).setFilter(dateFilter);
        grid.setAutoExpandColumn(autoExpandColumnField.getName());
	}
	
}